﻿Public Class ctrThucDon

    Private Sub ShowTab()
        Dim i As Integer = frmMain.TabControl1.TabCount - 1
        frmMain.TabControl1.SelectTab(i)
    End Sub

    Private Function ExistsTab(ByVal str As String) As Integer
        For i = 0 To frmMain.TabControl1.TabCount() - 1 Step 1
            If (frmMain.TabControl1.TabPages(i).Text = str) Then
                Return i
            End If
        Next
        Return -1
    End Function

    Private Sub btnGoiMon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGoiMon.Click
        Dim str As String = "Gọi món"
        If (ExistsTab(str) = -1) Then
            Dim tab As TabPage = New TabPage()
            frmMain.TabControl1.Controls.Add(tab)
            tab.Text = str

            Dim ctr As ctrGoiMon = New ctrGoiMon()
            tab.Controls.Add(ctr)
            ctr.Dock = DockStyle.Fill

            ShowTab()
        Else
            frmMain.TabControl1.SelectTab(ExistsTab(str))
        End If

        'effect
        btnChinhSua.ForeColor = Color.Green
        btnChinhSua.BackColor = Color.White
        btnGoiMon.ForeColor = Color.White
        btnGoiMon.BackColor = Color.Green
        btnTraCuu.ForeColor = Color.Green
        btnTraCuu.BackColor = Color.White
    End Sub

    Private Sub btnChinhSua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChinhSua.Click
        Dim str As String = "Chỉnh sửa thực đơn"
        If (ExistsTab(str) = -1) Then
            Dim tab As TabPage = New TabPage()
            frmMain.TabControl1.Controls.Add(tab)
            tab.Text = str

            Dim ctr As ctrChinhSuaTD = New ctrChinhSuaTD()
            tab.Controls.Add(ctr)
            ctr.Dock = DockStyle.Fill

            ShowTab()
        Else
            frmMain.TabControl1.SelectTab(ExistsTab(str))
        End If

        'effect
        btnChinhSua.ForeColor = Color.White
        btnChinhSua.BackColor = Color.Green
        btnGoiMon.ForeColor = Color.Green
        btnGoiMon.BackColor = Color.White
        btnTraCuu.ForeColor = Color.Green
        btnTraCuu.BackColor = Color.White
    End Sub

    Private Sub btnTraCuu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTraCuu.Click
        Dim str As String = "Tra cứu thực đơn"
        If (ExistsTab(str) = -1) Then
            Dim tab As TabPage = New TabPage()
            frmMain.TabControl1.Controls.Add(tab)
            tab.Text = str

            Dim ctr As ctrTraCuuTD = New ctrTraCuuTD()
            tab.Controls.Add(ctr)
            ctr.Dock = DockStyle.Fill

            ShowTab()
        Else
            frmMain.TabControl1.SelectTab(ExistsTab(str))
        End If

        'effect
        btnChinhSua.ForeColor = Color.Green
        btnChinhSua.BackColor = Color.White
        btnGoiMon.ForeColor = Color.Green
        btnGoiMon.BackColor = Color.White
        btnTraCuu.ForeColor = Color.White
        btnTraCuu.BackColor = Color.Green
    End Sub
End Class
